<?php

// 网站信息分类表

namespace app\console\model;

use think\Db;
use think\Cache;
use think\Model;
use think\Request;

class InformationType extends Model
{
    // 模型事件
    protected static function init()
    {
        // 新增前
        self::event('before_write', function ($data) {
            $data->picUrl = uploadImg('picUrl', 'shop');
            $data->parentStr = parentStr(Request::instance()->param('parenTid'), 'information_type', Request::instance()->param('id'), Request::instance()->param('redId'), 'information');
            $data->count = ruleCount(Request::instance()->param('parenTid'), 'information_type');
            $data->update_time = date('Y-m-d',time());
        });
    }

    // 删除方法
    public static function amputate($id)
    {

        if (self::where('parentStr', 'like', '%,' . $id . ',%')->whereOr('id', $id)->delete()) {

            return true;

        }

        return false;

    }

    // 全部删除方法
    public static function amputateAll($id)
    {

        foreach ($id as $value) {

            self::where('parentStr', 'like', '%,' . $value . ',%')->whereOr('id', $value)->delete();
        }

        return true;

    }
}